chrome.extension.onConnect.addListener(function (port) {
    console.assert(port.name == 'flickrgrouppooltagchecker');

    port.onMessage.addListener(function (msg) {
        if (msg.name == 'getVersion') {
            new Request({
                url: "manifest.json",
                onSuccess: function (responseText, responseXML) {
                    var data;
                    try {
                       data = JSON.parse(responseText);
                    } catch (e) {
                        port.postMessage({callbackEvent: msg.callbackEvent, callbackId: msg.callbackId, stat: 'error', statusText: e});
                        return;
                    }
                    port.postMessage({callbackEvent: msg.callbackEvent, callbackId: msg.callbackId, stat: 'success', version: data.version});
                },
                onFailure: function (response) {
                    port.postMessage({callbackEvent: msg.callbackEvent, callbackId: msg.callbackId, stat: 'error', statusText: response.statusText});
                }
	    }).get();
	}
    });
});
